package edu.nju;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
 * format : dir/subdir/target.jar
 */
public class ArchivedEntry extends Entry{
    public ArchivedEntry(String classpath) {
        super(classpath);
    }

    @Override
    public byte[] readClassFile(String className) throws IOException {
		String jarName =this.classpath;
        JarFile jarFile = new JarFile(jarName);
        
		Enumeration<JarEntry> entrys = jarFile.entries();
		while (entrys.hasMoreElements()) {
			JarEntry jarEntry = entrys.nextElement();
			String temp=jarEntry.getName();
			temp = IOUtil.transform(temp);
			if (temp.contains(className)) {
			   	try {
	                
			   		InputStream inputStream =jarFile.getInputStream(jarEntry);
			        return IOUtil.readFileByBytes(inputStream);}
			    	catch(IOException e) {
			    		return null;
			}
		}
		}
        return null;
    
}
}
